package com.enjoyor.soa.traffic.rest.efoms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.filter.SSOClientfilter;
import com.enjoyor.soa.traffic.api.dto.efoms.CheckRecodeInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.DeviceStatusInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.RepairsInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.ICheckRecordInfoConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/checkRecord" })
@Api("CheckRecordInfoController")
@CrossOrigin

public class CheckRecordInfoController {

	@Autowired
	private ICheckRecordInfoConsumeService checkRecordInfoConsumeService;

	/**
	 * 根据编号ID查询巡检记录
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getCheckRecordInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = CheckRecodeInfoDto.class, code = 0, message = "")
	@ApiOperation("根据编号ID查询巡检记录")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "CheckRecordInfoId", value = "巡检记录编号", paramType = "query", dataType = "String") })
	public ResultPojo getCheckRecordInfo(
			@RequestParam(defaultValue = "", value = "CheckRecordInfoId", required = false) String CheckRecordInfoId,
			HttpServletRequest request) {
		return checkRecordInfoConsumeService.getCheckRecordInfo(CheckRecordInfoId);
	}

	/**
	 * 获取巡检记录List
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getCheckRecordInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = CheckRecodeInfoDto.class, code = 0, message = "")
	@ApiOperation("获取巡检记录List")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "CheckRecordInfoId", value = "巡检记录编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devId", value = "设备编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "checkPersonCode", value = "巡检人员编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devAreaCode", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devAreaName", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "checkPersonName", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devCategoryCode", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devTypeCode", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "checkResultCode", value = "结束时间", paramType = "query", dataType = "String") })
	public ResultPojo getCheckRecordInfoList(
			@RequestParam(defaultValue = "", value = "CheckRecordInfoId", required = false) String CheckRecordInfoId,
			@RequestParam(defaultValue = "", value = "devId", required = false) String devId,
			@RequestParam(defaultValue = "", value = "checkPersonCode", required = false) String checkPersonCode,
			@RequestParam(defaultValue = "", value = "checkTime", required = false) String startTime,
			@RequestParam(defaultValue = "", value = "endTime", required = false) String endTime,
			@RequestParam(defaultValue = "", value = "devAreaCode", required = false) String devAreaCode,
			@RequestParam(defaultValue = "", value = "devAreaName", required = false) String devAreaName,
			@RequestParam(defaultValue = "", value = "checkPersonName", required = false) String checkPersonName,
			@RequestParam(defaultValue = "", value = "devCategoryCode", required = false) String devCategoryCode,
			@RequestParam(defaultValue = "", value = "devTypeCode", required = false) String devTypeCode,
			@RequestParam(defaultValue = "", value = "checkResultCode", required = false) String checkResultCode,
			HttpServletRequest request) {
		return checkRecordInfoConsumeService.getCheckRecodeInfoList(CheckRecordInfoId, devId, checkPersonCode,
				startTime, endTime, devAreaCode, devAreaName, checkPersonName, devCategoryCode, devTypeCode,
				checkResultCode);
	}

	/**
	 * 获取巡检记录List
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getCheckRecordInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = CheckRecodeInfoDto.class, code = 0, message = "")
	@ApiOperation("获取巡检记录Page")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "CheckRecordInfoId", value = "巡检记录编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devId", value = "设备编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "checkPersonCode", value = "巡检人员编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devAreaCode", value = "区域编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devAreaName", value = "区域名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "checkPersonName", value = "巡检人名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devCategoryCode", value = "巡检人编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devTypeCode", value = "设备类型编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "checkResultCode", value = "巡检结果编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devName", value = "设备名称", paramType = "query", dataType = "String")})
	public ResultPojo getCheckRecordInfoPage(
			@RequestParam(defaultValue = "", value = "CheckRecordInfoId", required = false) String CheckRecordInfoId,
			@RequestParam(defaultValue = "", value = "devId", required = false) String devId,
			@RequestParam(defaultValue = "", value = "checkPersonCode", required = false) String checkPersonCode,
			@RequestParam(defaultValue = "", value = "startTime", required = false) String startTime,
			@RequestParam(defaultValue = "", value = "endTime", required = false) String endTime,
			@RequestParam(defaultValue = "", value = "devAreaCode", required = false) String devAreaCode,
			@RequestParam(defaultValue = "", value = "devAreaName", required = false) String devAreaName,
			@RequestParam(defaultValue = "", value = "checkPersonName", required = false) String checkPersonName,
			@RequestParam(defaultValue = "", value = "devCategoryCode", required = false) String devCategoryCode,
			@RequestParam(defaultValue = "", value = "devTypeCode", required = false) String devTypeCode,
			@RequestParam(defaultValue = "", value = "checkResultCode", required = false) String checkResultCode,
			@RequestParam(defaultValue = "", value = "devName", required = false) String devName,
			Page page, HttpServletRequest request) {
		return checkRecordInfoConsumeService.getCheckRecordInfoPage(CheckRecordInfoId, devId, checkPersonCode,
				startTime, endTime, devAreaCode, devAreaName, checkPersonName, devCategoryCode, devTypeCode,
				checkResultCode,devName, page);
	}

	/**
	 * 更新 巡检记录
	 * 
	 * @param checkRecodeInfoDto
	 * @param request
	 * @return
	 */
	@PutMapping(value = { "/updateCheckRecordInfo" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("更新巡检记录")
	public ResultPojo updateCheckRecordInfo(@RequestBody CheckRecodeInfoDto checkRecodeInfoDto,
			HttpServletRequest request) {
		return checkRecordInfoConsumeService.updateCheckRecordInfo(checkRecodeInfoDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	/**
	 * 添加 巡检记录
	 * 
	 * @param checkRecodeInfoDto
	 * @param request
	 * @return
	 */
	@GetMapping(value = { "/insertCheckRecordInfo" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("增加巡检记录")
	@ApiImplicitParams({ @ApiImplicitParam(name = "list", value = "新建记录集合", paramType = "query", dataType = "String")})
	public ResultPojo insertCheckRecordInfo(
			@RequestParam(defaultValue = "", value = "list", required = false) String list,
			HttpServletRequest request) {
		String token = (String) request.getAttribute("token");//获取token；
		com.enjoyor.soa.traffic.api.uums.dto.UserDto userDto = SSOClientfilter.getUserInfo(token);
		return checkRecordInfoConsumeService.insertCheckRecordInfo(list,userDto);
	}

	@DeleteMapping(value = { "/deleteCheckRecordInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("删除巡检记录")
	@ApiImplicitParam(name = "CheckRecordInfoId", value = "报修单编号", paramType = "query", required = true, dataType = "String")
	public ResultPojo deleteCheckRecordInfo(@RequestParam("CheckRecordInfoId") String CheckRecordInfoId,
			HttpServletRequest request) {
		return checkRecordInfoConsumeService.delCheckRecordInfo(CheckRecordInfoId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
}
